<?php

namespace App\Http\Controllers\System;

use App\Http\Controllers\BaseAdminController;
use App\Lib\Enum\Params;
use App\Service\SiteService;

class SiteController extends BaseAdminController {
    protected $siteService;

    public function _init() {
        $this->siteService = new SiteService();
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {
        $sites = $this->siteService->getSiteList();
        return view("system.site.index", ['siteList' => $sites]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create() {
        return view("system.site.create");
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store() {
        $data = $this->request->get('data');
        $site = $this->siteService->add($data);
        return $this->success($site, "添加成功");
    }

    /**
     * Display the specified resource.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function show($id) {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id) {
        $site = $this->siteService->getSiteById($id);
        return view("system.site.edit", ['site' => $site]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function update($id) {
        $data = $this->request->get('data');
        $site = $this->siteService->update($id, $data);
        if ($site) {
            return $this->success($site, "编辑成功");
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id) {
        //
    }
}
